package com.kfm.pm;

import java.util.Random;

public class Demo03 {

    public static void main(String[] args) {
        // 指定数组的指定位置添加一个数据
        int[] nums = {2, 4, -1, 0, 9,8};
        int key = 20;
        int index = 3;
        int[] newArr = new int[nums.length + 1];
        addElement(nums, index, key, newArr);
        for (int i : newArr) {
            System.out.println(i);
        }
    }

    // 指定数组的指定位置添加一个数据
    public static void addElement(int[] dest, int index, int key, int[] target) {
        System.arraycopy(dest, 0, target, 0, index);
        target[index] = key;
        System.arraycopy(dest, index, target, index + 1, dest.length - index);
    }


}
